package net.lab1024.smartadmin.module.business.drivecycle.controller;

import net.lab1024.smartadmin.common.domain.PageResultDTO;
import net.lab1024.smartadmin.common.controller.BaseController;
import net.lab1024.smartadmin.common.domain.ResponseDTO;
import net.lab1024.smartadmin.common.domain.ValidateList;
import net.lab1024.smartadmin.module.business.atmosphere.domain.entity.AtmosphereEntity;
import net.lab1024.smartadmin.module.business.drivecycle.domain.dto.DrivecycleAddDTO;
import net.lab1024.smartadmin.module.business.drivecycle.domain.dto.DrivecycleUpdateDTO;
import net.lab1024.smartadmin.module.business.drivecycle.domain.dto.DrivecycleQueryDTO;
import net.lab1024.smartadmin.module.business.drivecycle.domain.entity.DrivecycleEntity;
import net.lab1024.smartadmin.module.business.drivecycle.domain.vo.DrivecycleVO;
import net.lab1024.smartadmin.module.business.drivecycle.domain.vo.DrivecycleExcelVO;
import net.lab1024.smartadmin.module.business.drivecycle.service.DrivecycleService;
import cn.afterturn.easypoi.excel.ExcelExportUtil;
import cn.afterturn.easypoi.excel.entity.ExportParams;
import net.lab1024.smartadmin.module.business.drivingCycle.domain.entity.DrivingCycleEntity;
import net.lab1024.smartadmin.util.SmartRequestTokenUtil;
import org.apache.poi.ss.usermodel.Workbook;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.Date;
import java.util.List;

/**
 * [ 行驶工况特性曲线 (drivecycle) UPDATE  ]
 *
 * @author wuhq
 * @version 1.0
 * @company 汽车传动
 * @copyright (c)  汽车传动Inc. All rights reserved.
 * @date 2021-10-29 20:37:47
 * @since JDK1.8
 */
@RestController
@Api(tags = {"行驶工况特性曲线 (drivecycle) UPDATE "})
public class DrivecycleController extends BaseController {

    @Autowired
    private DrivecycleService drivecycleService;

    @ApiOperation(value = "根据id获取数据",notes = "@author 何杺")
    @GetMapping("/drivecycle/getById/{id}")
    public ResponseDTO<DrivecycleEntity> getById(@PathVariable Long id) {
        return ResponseDTO.succData(drivecycleService.getById(id));
    }

    @ApiOperation(value = "分页查询行驶工况特性曲线 (drivecycle) UPDATE ",notes = "@author wuhq")
    @PostMapping("/drivecycle/page/query")
    public ResponseDTO<PageResultDTO<DrivecycleVO>> queryByPage(@RequestBody DrivecycleQueryDTO queryDTO) {
        if(queryDTO.getCreateUser()!=null){
            queryDTO.setCreateUser(SmartRequestTokenUtil.getRequestUserId());
        }
        return drivecycleService.queryByPage(queryDTO);
    }

    @ApiOperation(value = "添加行驶工况特性曲线 (drivecycle) UPDATE ",notes = "@author wuhq")
    @PostMapping("/drivecycle/add")
    public ResponseDTO<String> add(@RequestBody @Validated DrivecycleAddDTO addTO){
        addTO.setCreateUser(SmartRequestTokenUtil.getRequestUserId());
        addTO.setCreateTime(new Date());
        return drivecycleService.add(addTO);
    }

    @ApiOperation(value="修改行驶工况特性曲线 (drivecycle) UPDATE ",notes = "@author wuhq")
    @PostMapping("/drivecycle/update")
    public ResponseDTO<String> update(@RequestBody @Validated DrivecycleUpdateDTO updateDTO){
        return drivecycleService.update(updateDTO);
    }

    @ApiOperation(value="批量删除行驶工况特性曲线 (drivecycle) UPDATE ",notes = "@author wuhq")
    @PostMapping("/drivecycle/deleteByIds")
    public ResponseDTO<String> delete(@RequestBody @Validated ValidateList<Long> idList) {
        return drivecycleService.deleteByIds(idList);
    }

    @ApiOperation(value = "批量导出", notes = "@author wuhq")
    @PostMapping("/drivecycle/export/batch")
    public void batchExport(@RequestBody @Validated ValidateList<Long> idList, HttpServletResponse response) {
        //查询数据
        List<DrivecycleExcelVO> drivecycleList = drivecycleService.queryBatchExportData(idList);
        //导出操作
        ExportParams ex = new ExportParams("行驶工况特性曲线 (drivecycle) UPDATE ", "Sheet1");
        Workbook workbook = ExcelExportUtil.exportExcel(ex, DrivecycleExcelVO.class, drivecycleList);
        downloadExcel("行驶工况特性曲线 (drivecycle) UPDATE ", workbook, response);
    }

    @ApiOperation(value = "导出全部", notes = "@author wuhq")
    @PostMapping("/drivecycle/export/all")
    public void exportAll(@RequestBody @Validated DrivecycleQueryDTO queryDTO, HttpServletResponse response) {
        //查询数据
        List<DrivecycleExcelVO> drivecycleList = drivecycleService.queryAllExportData(queryDTO);
        //导出操作
        ExportParams ex = new ExportParams("行驶工况特性曲线 (drivecycle) UPDATE ", "Sheet1");
        Workbook workbook = ExcelExportUtil.exportExcel(ex, DrivecycleExcelVO.class, drivecycleList);
        downloadExcel("行驶工况特性曲线 (drivecycle) UPDATE ", workbook, response);
    }

}
